类型转换:把一个值从一种数据类型变为另一种数据类型的过程,常见于编程中(如把字符串转为整数、把浮点数转为整数等)。类型转换可能是隐式(自动发生)或显式(通过转换函数/强制转换写出来)。不同语言对范围溢出、精度丢失、错误处理的规则不同。
/taɪp kənˈvɝːʒən/
I used type conversion to turn the string into a number.
我用了类型转换把字符串变成数字。
In strongly typed languages, type conversion rules affect safety, performance, and whether a program compiles at all.
在强类型语言中,类型转换规则会影响安全性、性能,甚至决定程序能否通过编译。
type 源自希腊语 typos,本义与“印模、模子、类型”相关,引申为“类别/类型”;conversion 来自拉丁语 convertere(con- “一起” + vertere “转动/改变方向”),表示“转变、转换”。合起来即“把类型改变/转换”。